package com.niuke;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 45. 阿里巴巴找黄金宝箱(Ⅳ)
 * https://www.bilibili.com/read/cv24515977
 */
public class NiukeMoni45 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] input = scanner.nextLine().split(",");
        int[] data = new int[input.length];
        for (int i = 0; i < input.length; i++) {
            data[i] = Integer.parseInt(input[i]);
        }

        int[] res = new int[input.length];
        int max = Arrays.stream(data).max().getAsInt();

        for (int i = 0; i < data.length; i++) {
            if (data[i] == max) {
                res[i] = -1;
            } else if (i == data.length - 1) {
                for (int k = 0; k < i; k++) {
                    if (data[k] > data[i]) {
                        res[i] = data[k];
                        break;
                    }
                }
            } else {
                for (int j = i + 1; j < data.length; j++) {
                    if (data[j] > data[i]) {
                        res[i] = data[j];
                        break;
                    }

                    if (j == data.length - 1 && data[j] <= data[i]) {
                        for (int k = 0; k < i; k++) {
                            if (data[k] > data[i]) {
                                res[i] = data[k];
                                break;
                            }
                        }
                    }
                }
            }
        }

        System.out.println(Arrays.toString(res));

    }

}
